//
//  CustomerHeadView.m
//  mendianjieke
//
//  Created by 响当当 on 7/31/19.
//  Copyright © 2019 dongzheng. All rights reserved.
//

#import "CustomerHeadView.h"

@interface CustomerHeadView()

@property (nonatomic, strong)UIImageView *headImageView;//头像
@property (nonatomic, strong)UILabel *genderLabrl;//性别
@property (nonatomic, strong)UILabel *ageLabel;//年龄
@property (nonatomic, strong)UILabel *vipLabel;//头像
@property (nonatomic, strong)UILabel *customerHOrderLabel;//最高客单
@property (nonatomic, strong)UILabel *customerLOrderLabel;//最低客单
@property (nonatomic, strong)UILabel *averageOrderLabel;//平均客单
@property (nonatomic, strong)UILabel *normalTimeLabel;//正常周期
@property (nonatomic, strong)UILabel *liveTimeLabel;//生命周期

@end

@implementation CustomerHeadView

- (UIImageView *)headImageView
{
    if (!_headImageView)
    {
        UIImageView *bgImageView = [[UIImageView alloc]initWithFrame:CGRectMake(20*kUIScaleBasePlus,20*kUIScaleBasePlus,110*kUIScaleBasePlus,110*kUIScaleBasePlus)];
               bgImageView.image = [UIImage imageNamed:@"photoBG"];
        [self addSubview:bgImageView];
        
        _headImageView = [[UIImageView alloc]initWithFrame:CGRectMake(25*kUIScaleBasePlus,30*kUIScaleBasePlus,100*kUIScaleBasePlus,100*kUIScaleBasePlus)];
//        _headImageView.backgroundColor = [UIColor redColor];
        
    }
    return _headImageView;
}

- (UILabel *)genderLabrl
{
    if (!_genderLabrl)
    {
        _genderLabrl = [Utilties creatLabelWithFrame:CGRectMake(20*kUIScaleBasePlus,CGRectGetMaxX(self.headImageView.frame)+15.5*kUIScaleBasePlus,120*kUIScaleBasePlus,11.5*kUIScaleBasePlus)
                                     textAligment:NSTextAlignmentLeft
                                         textClor:LCHexColor(0x000000)
                                         textFont:11*kUIScaleBasePlus];
        
    }
    return _genderLabrl;
}

- (UILabel *)ageLabel
{
    if (!_ageLabel)
    {
        _ageLabel = [Utilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(self.headImageView.frame)+15*kUIScaleBasePlus,CGRectGetMaxY(self.genderLabrl.frame)+5*kUIScaleBasePlus,200*kUIScaleBasePlus,20*kUIScaleBasePlus)
                                     textAligment:NSTextAlignmentLeft
                                         textClor:LCHexColor(0x282828)
                                         textFont:14*kUIScaleBasePlus];
        
    }
    return _ageLabel;
}

- (UILabel *)vipLabel
{
    if (!_vipLabel)
    {
        _vipLabel = [Utilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(self.headImageView.frame)+15*kUIScaleBasePlus,CGRectGetMaxY(self.ageLabel.frame)+5*kUIScaleBasePlus,200*kUIScaleBasePlus,20*kUIScaleBasePlus)
                                     textAligment:NSTextAlignmentLeft
                                         textClor:LCHexColor(0x282828)
                                         textFont:14*kUIScaleBasePlus];
        
    }
    return _vipLabel;
}

- (UILabel *)customerHOrderLabel
{
    if (!_customerHOrderLabel)
    {
        _customerHOrderLabel = [Utilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(self.headImageView.frame)+20.5*kUIScaleBasePlus,20*kUIScaleBasePlus,189*kUIScaleBasePlus,28*kUIScaleBasePlus)
                                     textAligment:NSTextAlignmentLeft
                                         textClor:LCHexColor(0x545454)
                                         textFont:11*kUIScaleBasePlus];
        _customerHOrderLabel.backgroundColor = LCHexColor(0xF0F0F0);
        
    }
    return _customerHOrderLabel;
}

- (UILabel *)customerLOrderLabel
{
    if (!_customerLOrderLabel)
    {
        _customerLOrderLabel = [Utilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(self.headImageView.frame)+20.5*kUIScaleBasePlus,CGRectGetMaxY(self.customerHOrderLabel.frame)+8*kUIScaleBasePlus,189*kUIScaleBasePlus,28*kUIScaleBasePlus)
                                     textAligment:NSTextAlignmentLeft
                                         textClor:LCHexColor(0x545454)
                                         textFont:11*kUIScaleBasePlus];
        _customerLOrderLabel.backgroundColor = LCHexColor(0xF0F0F0);
    }
    return _customerLOrderLabel;
}

- (UILabel *)averageOrderLabel
{
    if (!_averageOrderLabel)
    {
        _averageOrderLabel = [Utilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(self.headImageView.frame)+20.5*kUIScaleBasePlus,CGRectGetMaxY(self.customerLOrderLabel.frame)+8*kUIScaleBasePlus,189*kUIScaleBasePlus,28*kUIScaleBasePlus)
                                     textAligment:NSTextAlignmentLeft
                                         textClor:LCHexColor(0x545454)
                                         textFont:11*kUIScaleBasePlus];
        _averageOrderLabel.backgroundColor = LCHexColor(0xF0F0F0);

    }
    return _averageOrderLabel;
}

- (UILabel *)normalTimeLabel
{
    if (!_normalTimeLabel)
    {
        UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.headImageView.frame)+20.5*kUIScaleBasePlus,CGRectGetMaxY(self.averageOrderLabel.frame)+12*kUIScaleBasePlus,64*kUIScaleBasePlus,48*kUIScaleBasePlus)];
        bgView.backgroundColor = LCHexColor(0x02C899);
        [self addSubview:bgView];
        
        UILabel *titleLabel = [Utilties creatLabelWithFrame:CGRectMake(0,5*kUIScaleBasePlus,64*kUIScaleBasePlus,10.5*kUIScaleBasePlus)
                                               textAligment:NSTextAlignmentCenter
                                                   textClor:LCHexColor(0xFFFFFF)
                                                   textFont:11*kUIScaleBasePlus];
        titleLabel.text = @"正常周期";
        [bgView addSubview:titleLabel];
        
        UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(12*kUIScaleBasePlus,CGRectGetMaxY(titleLabel.frame)+5*kUIScaleBasePlus,40*kUIScaleBasePlus,0.5*kUIScaleBasePlus)];
        lineView.backgroundColor = LCHexColor(0xFFFFFF);
        [bgView addSubview:lineView];
        
        _normalTimeLabel = [Utilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(self.headImageView.frame)+20.5*kUIScaleBasePlus,155*kUIScaleBasePlus,64*kUIScaleBasePlus,20*kUIScaleBasePlus)
                                     textAligment:NSTextAlignmentCenter
                                         textClor:LCHexColor(0xFFFFFF)
                                         textFont:16*kUIScaleBasePlus];
        
    }
    return _normalTimeLabel;
}

- (UILabel *)liveTimeLabel
{
    if (!_liveTimeLabel)
    {
        
        UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.normalTimeLabel.frame)+10*kUIScaleBasePlus,CGRectGetMaxY(self.averageOrderLabel.frame)+12*kUIScaleBasePlus,64*kUIScaleBasePlus,48*kUIScaleBasePlus)];
        bgView.backgroundColor = LCHexColor(0xFF7D7D);
        [self addSubview:bgView];
        
        UILabel *titleLabel = [Utilties creatLabelWithFrame:CGRectMake(0,5*kUIScaleBasePlus,64*kUIScaleBasePlus,10.5*kUIScaleBasePlus)
                                               textAligment:NSTextAlignmentCenter
                                                   textClor:LCHexColor(0xFFFFFF)
                                                   textFont:11*kUIScaleBasePlus];
        titleLabel.text = @"生命周期";
        [bgView addSubview:titleLabel];
        
        UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(12*kUIScaleBasePlus,CGRectGetMaxY(titleLabel.frame)+5*kUIScaleBasePlus,40*kUIScaleBasePlus,0.5*kUIScaleBasePlus)];
        lineView.backgroundColor = LCHexColor(0xFFFFFF);
        [bgView addSubview:lineView];
        
        _liveTimeLabel = [Utilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(self.normalTimeLabel.frame)+10*kUIScaleBasePlus,155*kUIScaleBasePlus,64*kUIScaleBasePlus,20*kUIScaleBasePlus)
                                            textAligment:NSTextAlignmentCenter
                                                textClor:LCHexColor(0xFFFFFF)
                                                textFont:16*kUIScaleBasePlus];
        
    }
    return _liveTimeLabel;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self addSubview:self.headImageView];
        [self addSubview:self.genderLabrl];
        [self addSubview:self.customerHOrderLabel];
        [self addSubview:self.customerLOrderLabel];
        [self addSubview:self.averageOrderLabel];
        [self addSubview:self.normalTimeLabel];
        [self addSubview:self.liveTimeLabel];

    }
    return self;
}

- (void)getInfo:(NSArray *)arr headImage:(NSString *)photo
{
    self.genderLabrl.text = [NSString stringWithFormat:@"%@,%@岁,会员年龄%@",[arr[0] integerValue] == 0 ? @"女" : @"男",arr[1],arr[2]];
    
    NSString *customerHOrderStr = [NSString stringWithFormat:@"   最高客单：¥%@",arr[3]];
    self.customerHOrderLabel.attributedText = [customerHOrderStr addAttriButedString:customerHOrderStr Color:LCHexColor(0x212121) Font:[UIFont systemFontOfSize:18*kUIScaleBasePlus] rang:NSMakeRange(9,customerHOrderStr.length-9)];
    
    NSString *customerLOrderStr = [NSString stringWithFormat:@"   最低客单：¥%@",arr[4]];
    self.customerLOrderLabel.attributedText = [customerLOrderStr addAttriButedString:customerLOrderStr Color:LCHexColor(0x212121) Font:[UIFont systemFontOfSize:18*kUIScaleBasePlus] rang:NSMakeRange(9,customerLOrderStr.length-9)];
    
    NSString *averageOrderStr = [NSString stringWithFormat:@"   平均客单：¥%@",arr[5]];
    self.averageOrderLabel.attributedText = [averageOrderStr addAttriButedString:averageOrderStr Color:LCHexColor(0x212121) Font:[UIFont systemFontOfSize:18*kUIScaleBasePlus] rang:NSMakeRange(9,averageOrderStr.length-9)];
    
    self.normalTimeLabel.text = arr[6];
    
    self.liveTimeLabel.text = arr[7];
    
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:photo] placeholderImage:[UIImage imageNamed:@"Bitmap"]];

}

@end
